# cmake 运行最低版本
cmake_minimum_required(VERSION 3.0)

# 提供GNU编码标准定义的安装目录变量。
# https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
# 安装目录应该总是用变量命名，因此很容易安装在非标准位置。 下面描述了这些变量的标准名称以及它们在GNU包中应该具有的值。
# 它们基于标准的文件系统布局; 它的变体在GNU/Linux和其他现代操作系统中使用。
# 安装程序在调用 make(例如 make prefix=/usr install) 或 configure(例如 configure --prefix=/usr)时需要覆盖这些值。
# GNU包不应该试图猜测在它们被安装到的系统上，哪个值适合这些变量:
#   使用这里指定的默认设置，以便所有GNU包的行为相同，允许安装程序实现任何期望的布局。
# 所有安装目录及其父目录都应该在安装之前创建(如果需要的话)。
# CMAKE_INSTALL_<dir>
#   给定类型文件的目标。该值可以传递给相应文件类型的install()命令的DESTINATION选项。
# CMAKE_INSTALL_FULL_<dir>
#   从相应的CMAKE_INSTALL_<dir>值生成的绝对路径。如果该值不是绝对路径，则通常通过添加CMAKE_INSTALL_PREFIX变量的值来构造绝对路径。但是，也有一些特殊的情况，如下所述。
include(GNUInstallDirs)
message("${CMAKE_INSTALL_PREFIX}")                                     # /usr/local
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")             # /usr/local/bin
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SBINDIR}")            # /usr/local/sbin
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBEXECDIR}")         # /usr/local/libexec
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}")         # /usr/local/etc
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SHAREDSTATEDIR}")     # /usr/local/com
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALSTATEDIR}")      # /usr/local/var
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_RUNSTATEDIR}")        # /usr/local/var/run
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")             # /usr/local/lib
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")         # /usr/local/include
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_OLDINCLUDEDIR}")      # /usr/local//usr/include
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}")        # /usr/local/share
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}")            # /usr/local/share
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INFODIR}")            # /usr/local/share/info
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}")          # /usr/local/share/locale
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}")             # /usr/local/share/man
message("${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOCDIR}")             # /usr/local/share/doc/template


# BINDIR          user executables (bin)
# SBINDIR         system admin executables (sbin)
# LIBEXECDIR      program executables (libexec)
# SYSCONFDIR      read-only single-machine data (etc)
# SHAREDSTATEDIR  modifiable architecture-independent data (com)
# LOCALSTATEDIR   modifiable single-machine data (var)
# RUNSTATEDIR     run-time variable data (LOCALSTATEDIR/run)
# LIBDIR          object code libraries (lib or lib64 or lib/<multiarch-tuple> on Debian)
# INCLUDEDIR      C header files (include)
# OLDINCLUDEDIR   C header files for non-gcc (/usr/include)
# DATAROOTDIR     read-only architecture-independent data root (share)
# DATADIR         read-only architecture-independent data (DATAROOTDIR)
# INFODIR         info documentation (DATAROOTDIR/info)
# LOCALEDIR       locale-dependent data (DATAROOTDIR/locale)
# MANDIR          man documentation (DATAROOTDIR/man)
# DOCDIR          documentation root (DATAROOTDIR/doc/PROJECT_NAME)

# 设置安装路径的前缀(默认为"/usr/local")
set(CMAKE_INSTALL_PREFIX "/usr")

# 设置执行 make install 时哪个目标应该被 install 到哪个位置
install(TARGETS ${PROJECT_NAME} DESTINATION bin)   
# CMAKE_INSTALL_PREFIX + "bin" --> /usr/bin

# 还可添加 PERMISSIONS 来指定 rwx-rwx-rwx 等权限配置
# OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, 
# GROUP_READ, GROUP_WRITE, GROUP_EXECUTE, 
# WORLD_READ, WORLD_WRITE, WORLD_EXECUTE, 
# SETUID, and SETGID.
